package com.yidu.hbatsams.service.Impl;

import com.github.pagehelper.PageHelper;
import com.yidu.hbatsams.dao.AtsEmpCoachMapper;
import com.yidu.hbatsams.domain.AtsEmpCoach;
import com.yidu.hbatsams.service.emp.AtsEmpCoachService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 教练表的Service实现类
 */
@Service
public class AtsEmpCoachServiceImpl implements AtsEmpCoachService {
    @Resource
    AtsEmpCoachMapper atsEmpCoachMapper;


    /**
     * 查询所有+根据name进行模糊查询
     * @param pageNum
     * @param pageSize
     * @param coachName
     * @return
     */
    @Override
    public List<AtsEmpCoach> selectAll(Integer pageNum, Integer pageSize, String coachName,String startTime,String endTime) {
        PageHelper.startPage(pageNum, pageSize);
        List<AtsEmpCoach> ats = atsEmpCoachMapper.selectAll(coachName,startTime,endTime);
        return ats;
    }

    /**
     * 查询行数
     * @return
     */
    @Override
    public Long count() {
        return atsEmpCoachMapper.count();
    }

    /**
     * 逻辑删除
     * @param coachId
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Integer coachId) {
        return atsEmpCoachMapper.deleteByPrimaryKey(coachId);
    }

    /**
     * 新增
     * @param record
     * @return
     */
    @Override
    public int insert(AtsEmpCoach record) {

        record.setIsva(1);
        record.setCreatTime(new Date(System.currentTimeMillis()));
        int ats = atsEmpCoachMapper.insert(record);
        return ats;
    }

    /**
     * 修改
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKey(AtsEmpCoach record ) {
        record.setIsva(1);
        AtsEmpCoach ats = atsEmpCoachMapper.findById(record.getCoachId());
        record.setCreatTime(ats.getCreatTime());
        return atsEmpCoachMapper.updateByPrimaryKey(record);
    }

    /**
     * 查询教练员名称
     * @return
     */
    @Override
    public List<AtsEmpCoach> findByName() {
        return atsEmpCoachMapper.findByName();
    }

    /**
     * 运动教练
     * @return
     */
    @Override
    public List<AtsEmpCoach> findByExerName() {
        return atsEmpCoachMapper.findByExerName();
    }

    /**
     * 根据ID查询
     * @param coachId
     * @return
     */
    @Override
    public AtsEmpCoach findById(Integer coachId) {
        return atsEmpCoachMapper.findById(coachId);
    }

    /**
     * 根据教练员名称查询ID
     * @param coachName
     * @return
     */
    @Override
    public AtsEmpCoach findByCoachId(String coachName) {
        return atsEmpCoachMapper.findByCoachId(coachName);
    }

    /**
     * 根据ID查询教练员
     * @param coachId
     * @return
     */
    @Override
    public List<AtsEmpCoach> findByCoachName(Integer coachId) {
        return atsEmpCoachMapper.findByCoachName(coachId);
    }


    /**
     * 根据教练员主键查专业
     * @param coachId
     * @return
     */
    @Override
    public AtsEmpCoach selectexpert(Integer coachId) {
        return atsEmpCoachMapper.selectexpert(coachId);
    }


}
